<%@ page import="com.bdqn.t382.lx.pojo.SysUser" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<html>
<head>
    <title></title>
</head>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>
    table tr:nth-child(odd) {
        background-color: cornsilk;
    }

    a {
        color: red;
    }
</style>
<body>
<%--<%--%>
<%--    SysUser user = (SysUser) session.getAttribute("user");--%>
<%--    if (user == null) {--%>
<%--        response.sendRedirect("erro.jsp");--%>
<%--    }--%>
<%--%>--%>
<div align="center"><h3>${user.realName}欢迎您!</h3></div>
<div align="center">
    <h1>图书分页信息</h1>
    <table border="1" align="center">
        <tr>
            <th>ID</th>
            <th>书名</th>
            <th>作者</th>
            <th>时间</th>
            <th>类型</th>
            <th>操作</th>
        </tr>
        <c:forEach items="${page.list}" var="book">
            <tr>
                <td>${book.b_id}</td>
                <td>${book.b_name}</td>
                <td>${book.b_author}</td>
                <td><fmt:formatDate value="${book.b_time}" pattern="yyyy-MM-dd"></fmt:formatDate></td>
                <td>
                    <c:if test="${book.b_type==1}">计算机/软件</c:if>
                    <c:if test="${book.b_type==2}">小说/文摘</c:if>
                    <c:if test="${book.b_type==3}">杂项</c:if>
                </td>
                <td>
                    <a class="view" href="view?b_id=${book.b_id}">查看</a>
                    <a class="sc" href="delete?b_id=${book.b_id}">删除</a>
                </td>
            </tr>
        </c:forEach>
    </table>
    总记录数：${page.totalCount}
    总页数：${page.totalPageCount}
    当前为：${page.pageNo}页
    <a href="page?pageNo=1">首页</a>
    <a href="page?pageNo=${page.totalPageCount}">尾页</a>
    <c:if test="${page.pageNo>1}"><a href="page?pageNo=${page.pageNo-1}">上一页</a></c:if>
    <c:if test="${page.pageNo<page.totalPageCount}"><a href="page?pageNo=${page.pageNo+1}">下一页</a></c:if>
</div>
<div align="center"><a href="add">新增图书信息</a></div>
</body>
</html>
<script>
    $(document).ready(function () {
        $('.sc').click(function (event) {
            var confirmDelete = confirm('确定要删除该条数据吗？');
            if (!confirmDelete) {
                event.preventDefault();
            }
        });
    });
</script>